<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>空托盘出库</title>
    <script th:src="@{/js/jquery.min.js}"></script>
    <style>
        table {
            border: 2px solid #000000;
            cellspacing: 2px;
            cellpadding: 2px;
        }

        tr,td{
            border: 1px solid #000000;
        }
    </style>
</head>
<script>
    function search() {
        var trayCode = document.getElementById("trayCode").value;
        if(trayCode == null || trayCode == undefined || trayCode == ""){
            alert("请输入托盘条码");
            return;
        }
        if(trayCode.length != 8){
            alert("托盘条码不规范，请核对！");
            return;
        }
        $("#detailMsg1  tr:not(:first)").empty("");

        $.ajax({
            "url": "/pda/productIn/out?trayCode=" + trayCode,
            "type": "POST",
            "dataType": "json",
            "success": function (result) {
                var data = result.data;
                if (data.length > 0) {
                    var str = "";
                    for (var i = 0; i < data.length; i++) {

                        str = "<tr><td><input name='checkB' type='checkbox' style='width:25px;height: 25px;' id='checkB'></td><td contentEditable='true'>"
                            +"</td><td>" + data[i].productName + "</td><td>" + data[i].lotNo + "</td><td>" + data[i].supplierName + "</td><td>"
                            + data[i].outQuantity + "</td><td>" + data[i].stockId + "</td></tr>";
                        $("#detailMsg1").append(str);

                    }
                } else {
                    alert("托盘没有出库作业，请核对！");
                }
            }
        });
    }

    function finishOut() {
        var tray_code = document.getElementById("trayCode").value;
        if (tray_code == "") {
            alert("托盘条码不能为空！");
            return;
        }
        if (tray_code.length != 8) {
            alert("托盘条码不符合规范！");
            return;
        }
        var info2 = [];
        var arr = document.getElementsByName("checkB");
        for (var i = 0; i < arr.length; i++) {
            if (arr[i].checked == true) {
                info2.push({stock_id:arr[i].parentNode.parentNode.childNodes[6].innerText,quantity:arr[i].parentNode.parentNode.childNodes[1].innerText});
            }
        }
        var text={tray_code:tray_code,data:info2};
        //控制按钮多次点击
        var btn = document.getElementById('btn_submit');//首先需要获取的是哪一个按钮的id
        btn.disabled = 'disabled';//只要点击就将按钮的可点击的状态更改为不可以点击的状态
        setTimeout(function(){//设置时间，多久可以改变状态为可以点击
            btn.disabled = '';
        },5000);

        $.post("/pda/productIn/pdCKSure",{

        })
        $.ajax({
            "url": '/pda/productIn/pdCKSure',
            "type": 'post',
            "dataType": 'json',//后台返回数据格式
            "contentType": 'application/json',
            "data": JSON.stringify(text),
            "success": function (data) {
                alert(data.errorInfo);
                window.location.reload();
            }
        });
    }
</script>
<body>
<table id="dg" width="88%" height="55%">
    <tr>
        <td align="center">
            <label>托盘条码：</label>

            <input id="trayCode" type="text" oninput="search()">
            <button id="btn_submit" type="button" onclick="finishOut()">提交</button>
        </td>
    </tr>
    <tr>
        <td align="center" colspan="2">
            <table id="detailMsg1" name="detailMsg1">
                <tbody>
                <tr>
                    <td>请选择</td>
                    <td>实际数量</td>
                    <td>物资名称</td>
                    <td>批号</td>
                    <td>供应商</td>
                    <td>出库数量</td>
                    <td>库存编号</td>
                </tr>
                </tbody>
            </table>
        </td>
    </tr>



</table>
</body>

</html>